
package com.akupilih.app;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.akupilih.app.model.DBClass;
import com.viewpagerindicator.CirclePageIndicator;

public class WelcomeActivity extends FragmentActivity {
    /**
     * The number of pages (wizard steps) to show in this demo.
     */
    private static final int NUM_PAGES = 5;

    /**
     * The pager widget, which handles animation and allows swiping horizontally
     * to access previous and next wizard steps.
     */
    private ViewPager mPager;

    /**
     * The pager adapter, which provides the pages to the view pager widget.
     */
    private PagerAdapter mPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome_slide);

        // Instantiate a ViewPager and a PagerAdapter.
        mPager = (ViewPager) findViewById(R.id.pager);
        mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(mPagerAdapter);

        // Bind the title indicator to the adapter
        CirclePageIndicator titleIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
        titleIndicator.setViewPager(mPager);
    }

    @Override
    public void onBackPressed() {
        if (mPager.getCurrentItem() == 0) {
            // If the user is currently looking at the first step, allow the
            // system to handle the
            // Back button. This calls finish() on this activity and pops the
            // back stack.
            super.onBackPressed();
        } else {
            // Otherwise, select the previous step.
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    }

    /**
     * A simple pager adapter that represents 5 ScreenSlidePageFragment objects,
     * in sequence.
     */
    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
        public ScreenSlidePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            String slide_title = null;
            String slide_text = null;
            Drawable icon = null;

            if (position == 1) {
                slide_title = getResources().getString(R.string.activity_welcome_featured_1_title);
                slide_text = getResources().getString(R.string.activity_welcome_featured_1_info);
                icon = getResources().getDrawable(R.drawable.featured_profil);
            } else if (position == 2) {
                slide_title = getResources().getString(R.string.activity_welcome_featured_2_title);
                slide_text = getResources().getString(R.string.activity_welcome_featured_2_info);
                icon = getResources().getDrawable(R.drawable.featured_statistik);
            } else if (position == 3) {
                slide_title = getResources().getString(R.string.activity_welcome_featured_3_title);
                slide_text = getResources().getString(R.string.activity_welcome_featured_3_info);
                icon = getResources().getDrawable(R.drawable.featured_berita);
            } else {
                slide_title = getResources().getString(R.string.activity_welcome_featured_4_title);
                slide_text = getResources().getString(R.string.activity_welcome_featured_4_info);
                icon = getResources().getDrawable(R.drawable.featured_vote);
            }
            return new WelcomeFragment(slide_title, slide_text, icon, position);
        }

        @Override
        public int getCount() {
            return NUM_PAGES;
        }
    }

    public void mainActivity(View login) {
        Intent myIntent = new Intent(WelcomeActivity.this, MainActivity.class);
        WelcomeActivity.this.startActivity(myIntent);
        DBClass db = new DBClass(this);
        db.addConfig();
        this.finish();
    }
}
